<?php

global $lid,$listSummary,$logid;
global $listDAO,$errmsg;

require_once ( LIB_DIR.'classes/Pager.php' );


if( isset($_GET['p']) && is_numeric($_GET['p']) )
	$startPos = ( $_GET['p'] - 1 ) * LIST_PER_PAGE;
else
	$startPos = 0;
	
$currentURL = htmlspecialchars( $_SERVER["REQUEST_URI"] );
$currentURL = preg_replace( '/&p=[0-9]+/', "", $currentURL );


$priority = split( ' ', $listSummary['item_priority'] );


$result = $listDAO->GetListEntry( $lid, $startPos );
	
$entries = array();
$shop_ids = array();
$product_ids = array();
	
$totalCount = 0;
	
foreach ($result as $key => $value )		
{
    $entries[] = array(
    	'id' => $value['id'],
    	'description' => $value['description'],
    	'entry_type' => $value['entry_type'],
    	'entry_id' => $value['entry_id'],
    	'shop_name' => '',
        'plat_id' => '',
    	'product_name' => '',
    	'score'=>0,
    	'service' => 0,
    	'velocity' => 0,
    	'rate' => 0,
    	'reality' => 0,
    	'priority' => GetPriority( $priority, $value['entry_type'], $value['entry_id'] ),
    	'pic_path' => ''
    );
    
    if( $value['entry_type'] == 3 )
    	$product_ids[] = $value['entry_id'];
    else 
    	$shop_ids[] = $value['entry_id'];
}	   

$productDAO = GetProductDAO();
if( count($product_ids) > 0 )
{
	$result = $productDAO->GetProductSimpleInfo( $product_ids );
	if( $result )
	{
		foreach( $result as $key => $value )
		{
			$f = &FindItemByValue( $entries, 'entry_id', $value['id'] );
			$f['shop_name'] = $value['shop_name'];
			$f['plat_id'] = $value['plat_id'];	
		    $f['product_name'] = $value['product_name'];
		    $f['score'] = $value['score'];
		    $f['service'] = $value['service'];
		    $f['velocity'] = $value['velocity'];
		    $f['rate'] = $value['rate'];
		    $f['reality'] = $value['reality'];
		    $f['pic_path'] = $value['pic_path'];
		}
	}
}

$shopDAO = GetShopDAO();
if( count($shop_ids) > 0 )
{	
	$result = $shopDAO->GetShopSimpleInfo( $shop_ids );
	if( $result )
	{
		foreach( $result as $key => $value )
		{
			$f = &FindItemByValue( $entries, 'entry_id', $value['id'] );
			$f['shop_name'] = $value['shop_name'];
			$f['plat_id'] = $value['plat_id'];		
		    $f['score'] = $value['score'];	
		    $f['service'] = $value['service'];
		    $f['velocity'] = $value['velocity'];
		    $f['rate'] = $value['rate'];
		    $f['reality'] = $value['reality'];
		    $f['pic_path'] = $value['logo_url'];
		}
	}
}
	
foreach( $entries as $k => $v )
	$prios[$k] = $v['priority'];

array_multisort( $prios, SORT_NUMERIC, SORT_ASC, $entries );
    		
$breadcrumb = GetBreadcrumb();
$breadcrumb->add( "首页", EDP_DOMAIN );
$breadcrumb->add( "评单", edp_href_link(PAGENAME_LIST_SUMMARY) );
$breadcrumb->add( $listSummary['user_name'], edp_href_link(PAGENAME_USER_LIST,'uid='.$listSummary['user_id']) );
$breadcrumb->add( $listSummary['title'] );

$pageObj = new Pager( $currentURL, $listSummary['total'], LIST_PER_PAGE, $startPos, UP_RESULT_PAGE );


function GetPriority( $array_input, $type, $id )
{
	$i = 1;
	$t = $type == 3 ? 1 : 0;
	
	foreach( $array_input as $k => $v )
	{
		if( $v == "$id:$t" )
			return $i;
		$i++;
	}
}

	
?>
